//
//  JoinQuizMoreCell.m
//  WanCaiC8
//
//  Created by tangang on 2018/3/19.
//  Copyright © 2018年 tangang. All rights reserved.
//

#import "JoinQuizMoreCell.h"
#import "LotteryNumCell.h"
@interface JoinQuizMoreCell()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (nonatomic ,strong) UICollectionView *collectionView;
@end

@implementation JoinQuizMoreCell{
    QXLable         *labNum;
    LotteryNumType  lotteryNumType;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self=[super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        WS(weakSelf);
        labNum=[[QXLable alloc]initWithFount:12];
        labNum.text=@"第20170909期";
        [self.contentView addSubview:labNum];
        [labNum mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.bottom.equalTo(weakSelf.contentView);
            make.width.mas_equalTo(@100);
            make.left.equalTo(weakSelf.contentView).with.offset(10);
        }];
        
        [self.contentView addSubview:self.collectionView];
        [self.collectionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.top.bottom.equalTo(weakSelf.contentView);
            make.left.equalTo(labNum.mas_right);
        }];
        UIView *line=[[UIView alloc]init];
        line.backgroundColor=DEFAULTBGCOLOR;
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.equalTo(weakSelf.contentView);
            make.height.mas_equalTo(@.7);
        }];
    }
    return self;
}

- (void)setData:(LotteryRecordModel *)model andType:(LotteryNumType)type{
    self.model=model;
    lotteryNumType=type;
    labNum.text=[NSString stringWithFormat:@"第%@期",model.Issue];
    [self.collectionView reloadData];
}

#pragma mark - collectionView代理函数
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return self.model.numArr.count;
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    LotteryNumCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"LotteryNumCell" forIndexPath:indexPath];
    [cell setTitle:self.model.numArr[indexPath.row] andType:lotteryNumType];
    [cell setFount:12];
    return cell;
}

- (UICollectionView *)collectionView{
    if (!_collectionView) {
        UICollectionViewFlowLayout *flowLayout =
        [[UICollectionViewFlowLayout alloc] init];
        [flowLayout setItemSize:CGSizeMake(25, 25)];
        flowLayout.minimumLineSpacing=0;
        flowLayout.minimumInteritemSpacing=0;
        [flowLayout setScrollDirection:UICollectionViewScrollDirectionHorizontal];
        _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero
                                             collectionViewLayout:flowLayout];
        [_collectionView registerClass:[LotteryNumCell class] forCellWithReuseIdentifier:@"LotteryNumCell"];
        _collectionView.delegate = self;
        _collectionView.dataSource = self;
        _collectionView.backgroundColor = [UIColor whiteColor];
    }
    return _collectionView;
}

@end
